package com.film.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.film.dao.FilmDao;
import com.film.dao.FilmTypeDao;
import com.film.dao.SearchFilmDao;
import com.film.dao.impl.FilmDaoImpl;
import com.film.dao.impl.FilmTypeDaoImpl;
import com.film.dao.impl.SearchFilmDaoImpl;
import com.film.domain.Film;
import com.film.service.DirectorService;
import com.film.service.FilmService;
import com.film.service.PerformerService;

public class FilmServiceImpl implements FilmService {
	private FilmDao filmDao = new FilmDaoImpl();
	private SearchFilmDao searchFilmDao = new SearchFilmDaoImpl();
	private DirectorService dirService = new DirectorServiceImpl();
	private PerformerService perService = new PerformerServiceImpl();
	private FilmTypeDao typeDao = new FilmTypeDaoImpl();

	@Override
	public List<Film> selectHotFilm() {
		
		return hotFilmTypeAndDirectoe(filmDao.selectHotFilm(0));
	}

	@Override
	public List<Film> selectShowFilm() {
		
		return showFilmTypeAndDirectoe(filmDao.selectShowFilm(0));
	}

	@Override
	public Film selectOneFilm(int filmId) {
		
		return filmDao.selectOneFilm(filmId,0);
	}

	@Override
	public List<Film> hotFilmTypeAndDirectoe(List<Film> lists) {
		//该集合用来查询所有的电影信息
		List<Film> films = new ArrayList();
		//循环遍历取得Film_id用来做导演  演员  类型的查询
//		List<Film> lists = selectHotFilm();
		
		for(Film f:lists) {
			f.setPerformers(perService.selectFilmPerformer(f.getFilmId()));
			f.setDirectors(dirService.selectFilmDirector(f.getFilmId()));
			f.setFilmTypes(typeDao.selectFilmType(f.getFilmId()));
			films.add(f);
		}
		return films;
	}

	@Override
	public List<Film> showFilmTypeAndDirectoe(List<Film> lists) {
		//该集合用来查询所有的电影信息
				List<Film> films = new ArrayList();
//				//循环遍历取得Film_id用来做导演  演员  类型的查询
//				List<Film> lists = selectShowFilm();
				
				for(Film f:lists) {
					f.setPerformers(perService.selectFilmPerformer(f.getFilmId()));
					f.setDirectors(dirService.selectFilmDirector(f.getFilmId()));
					f.setFilmTypes(typeDao.selectFilmType(f.getFilmId()));
					films.add(f);
				}
				return films;
	}

	@Override
	public Film FilmOneTypeAndDirectoe(int film_id) {
		Film film = selectOneFilm(film_id);
		if(film !=null) {
			film.setPerformers(perService.selectFilmPerformer(film.getFilmId()));
			film.setDirectors(dirService.selectFilmDirector(film.getFilmId()));
			film.setFilmTypes(typeDao.selectFilmType(film.getFilmId()));
		}
		
		return film;
	}

	@Override
	public List<Film> selectAllFilm() {
		List<Film> films = new ArrayList();
		//查到所有的电影
		for(Film film:filmDao.selectAllFilm(0)) {
			//通过电影id查询其他信息
			film.setPerformers(perService.selectFilmPerformer(film.getFilmId()));
			film.setDirectors(dirService.selectFilmDirector(film.getFilmId()));
			film.setFilmTypes(typeDao.selectFilmType(film.getFilmId()));
			films.add(film);
		}
		return films;
	}

	@Override
	public List<String> selectFilmPlace() {
		// TODO Auto-generated method stub
		return filmDao.selectFilmPlace();
	}

	@Override
	public List<Film> searchFilm(String condition) {
		List<Film> films = searchFilmDao.searchFilms(condition);
		List<Film> searchFilms = new ArrayList<>();
		for(Film f:films) {
			Film film = this.FilmOneTypeAndDirectoe(f.getFilmId());
			searchFilms.add(film);
		}
		return searchFilms;
	}
	

	
	//用来做即将上映电影的模糊查询
		@Override
		public List<Film> selectFilmLimitShow(int pageNum,int isDelete) {
			int stripNum = 7;//默认分页的查询条数为5条
			
			int pageNums = (pageNum-1)*stripNum;
			
			return showFilmTypeAndDirectoe(filmDao.selectFilmLimitShow(pageNums, stripNum,isDelete));
		}

		@Override
		public List<Film> selectFilmLimitHot(int pageNum,int isDelete) {
			int stripNum = 7;//默认分页的查询条数为5条
			
			int pageNums = (pageNum-1)*stripNum;
			return hotFilmTypeAndDirectoe(filmDao.selectFilmLimitHot(pageNums, stripNum,isDelete));
		}
		
		

		@Override
		public int updateFilmReviewScore(String reviewScoreint, int film_id) {
			
			return filmDao.updateFilmReviewScore(reviewScoreint, film_id);
		}

		@Override
		public int updateFilm(int filmId,int isDelete) {
			// TODO Auto-generated method stub
			return filmDao.updateFilm(filmId,isDelete);
		}

		@Override
		public List<Film> selectOffTheShelfHotFilm() {
			// TODO Auto-generated method stub
			return hotFilmTypeAndDirectoe(filmDao.selectHotFilm(1));
		}

		@Override
		public List<Film> selectOffTheShelfShowFilm() {
			// TODO Auto-generated method stub
			return showFilmTypeAndDirectoe(filmDao.selectShowFilm(1));
		}

		@Override
		public int addFilm(Film film,int except) {
			
			return filmDao.addFilm(film,except);
		}

		@Override
		public int updateFilmInfo(Film film) {
			// TODO Auto-generated method stub
			return filmDao.updateFilmInfo(film);
		}

		@Override
		public int groundingFilm(int filmId) {
			// TODO Auto-generated method stub
			return filmDao.groundingFilm(filmId);
		}

		@Override
		public List<String> selectFilmShowTime() {
			// TODO Auto-generated method stub
			return filmDao.selectFilmShowTime();
		}


}
